package controller

import (
	"context"

	"github.com/tiger1103/gfast/v3/api/v1/wxappapi"
	"github.com/tiger1103/gfast/v3/internal/app/app/dao"
)

var NavController = new(navController)

type navController struct{}

func (c *navController) Get(ctx context.Context, req *wxappapi.GetNavReq) (res *wxappapi.GetNavRes, err error) {
	res = new(wxappapi.GetNavRes)
	res.NavInfo, err = dao.AppNav.Ctx(ctx).WherePri(req.Id).One()
	return
}

func (c *navController) List(ctx context.Context, req *wxappapi.ListNavReq) (res *wxappapi.ListNavRes, err error) {
	res = new(wxappapi.ListNavRes)
	res.Total, err = dao.AppNav.Ctx(ctx).Count()
	res.List, err = dao.AppNav.Ctx(ctx).Page(req.PageNum, req.PageSize).Order("description asc").All()
	return
}
